
package swb.api.com.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * Knife4j配置类
 * 用于配置Swagger文档的生成和展示
 */
@Configuration
@EnableKnife4j
@EnableSwagger2WebMvc
public class Knife4jConfig {

    @Value("${knife4j.basic-auth.username:swb}")
    private String username;

    @Value("${knife4j.basic-auth.password:Swb123!@#}")
    private String password;
    /**
     * 创建默认API文档配置Bean
     * 配置Swagger文档的基本信息、扫描包路径等参数
     *
     * @return Docket对象，用于构建Swagger文档
     */
    @Bean
    public Docket defaultApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
//                .groupName("默认接口")
                .select()
                // 指定扫描的API包路径
                .apis(RequestHandlerSelectors.basePackage("swb.api.com.api"))
                // 包含所有路径
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 构建API基本信息
     * 设置文档标题、描述、版本等元数据信息
     *
     * @return ApiInfo对象，包含API文档的基本信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API文档")
                .description("Knife4j增强文档")
                .version("1.0")
                .build();
    }
}